#include "LevelTimer.h"

#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "BitmapFont.h"
#include "Camera.h"
#include <sstream>

// Constructor
LevelTimer::LevelTimer(void)
{
	hours		= 0;
	minutes		= 0;
	seconds		= 0;
	timer		= 0.0f;
	isPaused	= false;
	hidden		= true;

	posX	= Camera::GetInstance()->ScreenWidth() - 32;
	posY	= 0;
	width	= 160;
	height	= 32;

	imageID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("Textures/Level Timer.png"));
}

// Destructor
LevelTimer::~LevelTimer(void)
{
}

void LevelTimer::Update(float deltaTime)
{
	if(isPaused == true)
		return;

	timer += deltaTime;

	seconds = static_cast<int>(timer) % 60;
	minutes = static_cast<int>(timer) / 60;
	hours = static_cast<int>(timer) / 3600;
}
void LevelTimer::Render(void) const
{
	//int alpha = 128;

	//int mouseX = CSGD_DirectInput::GetInstance()->MouseGetPosX();
	//int mouseY = CSGD_DirectInput::GetInstance()->MouseGetPosY();

	//if(mouseX > posX && mouseX < posX + width)
		//if(mouseY > posY && mouseY < posY + height)
			//alpha = 255;

	//CSGD_TextureManager::GetInstance()->Draw(imageID, posX, posY, 1.0f, 1.0f, nullptr, 0.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(alpha, 255, 255, 255));

	ostringstream time;

	time << "Time: ";
	if(hours < 10)
		time << "0";

	time << hours;

	time << ":";
	if(minutes < 10)
		time << "0";

	time << minutes;

	time << ":";
	if(seconds < 10)
		time << "0";

	time << seconds;

	BitmapFont::GetInstance()->Print(time.str(), 320.0f, 5.0f, 0, 200);
}
void LevelTimer::ResetTimer(void)
{
	hours		= 0;
	minutes		= 0;
	seconds		= 0;
	timer		= 0.0f;
}
void LevelTimer::PauseTimer(void)
{
	isPaused = true;
}
void LevelTimer::ResumeTimer(void)
{
	isPaused = false;
}
